import { login } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/local'

export default {
  namespaced: true,
  state () {
    return {
      token: getToken() || ''
    }
  },
  mutations: {
    setToken (state, token) {
      state.token = token
      setToken(token)
    },
    getToken (state) {
      state.token = ''
      removeToken()
    }
  },
  actions: {
    async loginAsync (context, mobile) {
      const res = await login(mobile)
      console.log(res)
      context.commit('setToken', res.data.token)
    }
  }
}
